//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.atm.comment;

import com.atm.ShopApplication;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;

@RunWith(SpringRunner.class)
@SpringBootTest(
        classes = {ShopApplication.class}
)
@WebAppConfiguration
public class BaseJunit {
    @Autowired
    WebApplicationContext webApplicationContext;
    protected MockMvc mockMvc;

    public BaseJunit() {
    }

    @Before
    public void setupMockMvc() {
        this.mockMvc = MockMvcBuilders.webAppContextSetup(this.webApplicationContext).build();
    }

    @Before
    public void initDatabase() {
    }

    @Test
    public void replace() {
        this.traverseFolder2((String)null);
    }

    public void traverseFolder2(String path) {
        if(path == null || "".equals(path)) {
            path = "D:\\JAVA\\Workspaces\\IdeaProjects\\atm-shop\\atm-core\\src\\main\\java\\com\\atm\\core";
        }

        File file = new File(path);
        if(file.exists()) {
            File[] files = file.listFiles();
            if(files.length == 0) {
                System.out.println("文件夹是空的!");
                return;
            }

            File[] var4 = files;
            int var5 = files.length;

            for(int var6 = 0; var6 < var5; ++var6) {
                File sourceFile = var4[var6];
                if(sourceFile.isDirectory()) {
                    System.out.println("文件夹:" + sourceFile.getAbsolutePath());
                    this.traverseFolder2(sourceFile.getAbsolutePath());
                } else {
                    System.out.println("文件:" + sourceFile.getAbsolutePath());
                    this.out(sourceFile,path);
                }
            }
        } else {
            System.out.println("文件不存在!");
        }

    }

    public void out(File sourceFile,String path) {
        path = path.replaceAll("\\\\","\\\\");
        String outPath = sourceFile.getPath().replaceAll("D:\\\\JAVA\\\\Workspaces\\\\IdeaProjects\\\\atm-shop\\\\atm-core\\\\src\\\\main\\\\java\\\\com\\\\atm\\\\core", "D:\\\\Desktop\\\\out");
        FileInputStream fis = null;
        BufferedInputStream bis = null;
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        FileOutputStream osw = null;

        try {
            fis = new FileInputStream(sourceFile);
            bis = new BufferedInputStream(fis);
            byte[] buf = new byte[1024];

            int len;
            while((len = bis.read(buf)) != -1) {
                baos.write(buf, 0, len);
            }

            byte[] buffer = baos.toByteArray();
            String result = new String(buffer, "utf-8");
            System.out.println(result);
            result = result.replaceAll("@author stylefeng", "@author atm");
            result = result.replaceAll("@author fengshuonan", "@author atm");
            result = result.replaceAll("guns", "atm");
            result = result.replaceAll("Guns", "Atm");
            //替换文件名
            outPath = outPath.replaceAll("Guns","Atm");

            File outFile = new File(outPath);
            if(!outFile.getParentFile().exists()) {
                outFile.getParentFile().mkdirs();
            }

            if(!outFile.exists()) {
                outFile.createNewFile();
            }

            osw = new FileOutputStream(outFile);
            osw.write(result.getBytes());
            osw.flush();
        } catch (Exception var20) {
            var20.printStackTrace();
        } finally {
            try {
                baos.close();
                bis.close();
                fis.close();
                osw.close();
            } catch (IOException var19) {
                var19.printStackTrace();
            }

        }

    }
}
